<?php

namespace app\common\model;

use think\Model;

/**
 * ============================================================================
 * DSMall多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 数据层模型
 */
class Ziwork extends Model {
    /**
     * 添加子客服
     */
    public function add($data)
    {
        return db('work_zi')->insertGetId($data);
    }
    /**
     * 修改子客服
     */
    public function edit($condition,$data)
    {
        return db('work_zi')->where($condition)->update($data);
    }
    /**
     * 删除子客服
     */
    public function del($condition)
    {
        return db('work_zi')->where($condition)->delete();
    }
    /**
     * 获取单个子客服信息
     */
    public function getInfo($condition,$field='*')
    {
        return db('work_zi')->where($condition)->field($field)->find();
    }
    /**
     * 获取子客服列表
     */
    public function getList($condition,$field='*',$page=0,$sanjiArr=[],$order='ds_work_zi.id desc')
    {
        if($page)
        {
            $res = db('work_zi')->where($condition)->field($field)
                ->join('ds_type_work w','w.id = ds_work_zi.typeid')
                ->order($order);
            if ($sanjiArr) {
                foreach ($sanjiArr as $value) {
                    $res = $res->whereOr(['ds_work_zi.area_id'=>array('like', "%," .$value . ",%")]);
                }
            }
            $res = $res->paginate($page,false,['query'=>request()->param()]);
            $this->page_info= $res;
            return $res->items();
        }else{
            return db('work_zi')->where($condition)->field($field)->order($order)->select();
        }
    }
    public function getInfo2($condition,$field='z.*,w.gid')
    {
        return db('work_zi as z')->where($condition)->join('ds_type_work w','w.id=z.typeid','left')->field($field)->find();
    }
}
?>
